package com.suedawn.bookmanagesystem.controller;

import com.suedawn.bookmanagesystem.dto.BookDetailDTO;
import com.suedawn.bookmanagesystem.dto.BookDetailQueryDTO;
import com.suedawn.bookmanagesystem.service.BookDetailService;
import com.suedawn.bookmanagesystem.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 图书详情控制器
 */
@RestController
@RequestMapping("/api/bookdetail")
@Api(tags = "图书详情管理接口")
@CrossOrigin(origins = "http://localhost:5174")
public class BookDetailController {
    @Autowired
    private BookDetailService bookDetailService;

    @GetMapping("/list")
    @ApiOperation("获取图书详情列表")
    public R listBookDetails(BookDetailQueryDTO dto) {
        return bookDetailService.listBookDetails(dto);
    }

    @GetMapping("/detail")
    @ApiOperation("获取图书详情")
    public R getBookDetail(@RequestParam("id") Integer id) {
        return bookDetailService.getBookDetail(id);
    }

    @PostMapping("/add")
    @ApiOperation("添加图书详情")
    public R addBookDetail(@RequestBody BookDetailDTO dto) {
        return bookDetailService.addBookDetail(dto);
    }

    @PutMapping("/update")
    @ApiOperation("更新图书详情")
    public R updateBookDetail(@RequestParam("id") Integer id, @RequestBody BookDetailDTO dto) {
        return bookDetailService.updateBookDetail(id, dto);
    }

    @DeleteMapping("/del")
    @ApiOperation("删除图书详情")
    public R deleteBookDetail(@RequestParam("id") Integer id) {
        return bookDetailService.deleteBookDetail(id);
    }

    @PutMapping("/location")
    @ApiOperation("更新图书详情的位置编码")
    public R updateLocationCode(@RequestParam("detailId") Integer detailId, 
                               @RequestParam("locationCode") String locationCode) {
        return bookDetailService.updateLocationCode(detailId, locationCode);
    }
} 